#include "../headers/StdAfx.h"
#include "../headers/Unit.h"


CUnit::CUnit(void)
{
}


CUnit::~CUnit(void)
{
}

void CUnit::Update (float dTime)
{
   // Check if we are dead (HP == 0) and ignore us (this will stop our render as well)
   // we will keep dead units hidden on the battlefield for the time being in case we want to allow ressurection etc. later
   if (RetrieveStat (HP) == 0)
      return;

   // Check For Input
   Input (dTime);

   // Common Update (will check for a position change etc.)
   CBase::Update(dTime, true);

   // Individual Unit Update
   // Change Anything unique to the unit

   // Call the Render
   Render (dTime);
}
   
void CUnit::Render (float dTime)
{
   // Send our information to the renderer and request a redraw

}

void CUnit::Input (float dTIme)
{
   // Check for any keys this unit would expect
   // eg. Mouse click select or arrow keys to move
}

void CUnit::AdjustStat (int nChange, int nStatID)
{
   // use a temp for cleaner code and easier logic
   int tempCheck = m_tStats.r_nStatistics[nStatID];

   // Check for max health (example for bounds on any stat later)
   // Check for HP
   if (nStatID == HP)
   {
      // Check > 0 and < Max Health
      if (tempCheck + nChange >= 0 && 
            tempCheck + nChange <= m_tStats.r_nStatistics[MAX_HP])
      {
         tempCheck += nChange;
      }
   }
   else
   {
      // Any other stat for now we will just change
      tempCheck += nChange;
   }
   
   // Modify our changed stat
   m_tStats.r_nStatistics[nStatID] = tempCheck;
}

int CUnit::RetrieveStat (int nStatID)
{
   // just return a copy of our current value
   return m_tStats.r_nStatistics[nStatID];
}